<%@ page import="java.util.ArrayList" %>
<%@ page import="tech.aistar.pojo.User" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/4/20
  Time: 10:01 上午
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>core - 核心的标签库</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        table,td{
            border:1px solid #ccc;
        }
        td{
            height: 35px;
            width: 100px;
            text-align: center;
        }
    </style>
</head>
<body>
    <%
        List<User> users = new ArrayList<User>();
        User u1 = new User("admin","123",1);
        User u2 = new User("tom","123",0);
        User u3 = new User("jack","123",1);
        User u4 = new User("jack2","123",0);
        User u5 = new User("jack3","123",2);
        User u6 = new User("jack4","123",0);

        users.add(u1);
        users.add(u2);
        users.add(u3);
        users.add(u4);
        users.add(u5);
        users.add(u6);

        request.setAttribute("users",users);
    %>
<%--    每个标签背后都会拥有一个java类来提供支持的--%>
    <c:if test="${empty users}">
        <h3>sorry,没有任何数据...</h3>
    </c:if>

    <c:if test="${!empty users}">
        <table>
            <thead>
                <tr>
                    <th>序号index</th>
                    <th>序号count</th>
                    <th>用户名</th>
                    <th>密码</th>
                    <th>角色</th>
                </tr>
            </thead>
            <tbody>
<%--                增强for循环--%>
               <c:forEach items="${users}" var="u" varStatus="vs" begin="0" end="5" step="1">
                       <c:if test="${vs.index % 2 == 0}">
                           <tr bgcolor="yellow">
                       </c:if>
                       <c:if test="${vs.index % 2 != 0}">
                           <tr>
                       </c:if>
                       <td>${vs.index}</td>
                       <td>${vs.count}</td>
                       <td>${u.username}</td>
                       <td>${u.password}</td>
                        <td>
                            <c:choose>
                                <c:when test="${u.power == 0}">超级管理员</c:when>
                                <c:when test="${u.power == 1}">教师</c:when>
                                <c:when test="${u.power == 2}">学生</c:when>
                                <c:otherwise>黑名单</c:otherwise>
                            </c:choose>
                        </td>
                   </tr>
               </c:forEach>
            </tbody>
        </table>
    </c:if>
    <hr>

<%--    <%--%>
<%--        String s = "admin";--%>
<%--        request.setAttribute("s",s);--%>
<%--    %>--%>
<%--    属性scope="page",默认会将这个变量放入到作用域中--%>
    <c:set value="admin" var="s" scope="request"></c:set>

    <c:out value="${s}"></c:out><br>

<%--    escapeXml="false" - 默认是true,设置成false之后可以解析出html标签--%>
    <c:out value="<font color='red'>${s}</font>" escapeXml="false"></c:out>

<%--    重定向 - 不需要加上项目的上下文路径的--%>
<%--    <c:redirect url="/user/loginView"></c:redirect>--%>

<%--    <c:remove var="s"></c:remove>--%>
</body>
</html>
